import axios from 'axios'
import { Notification } from 'element-ui';

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// 创建axios实例
const service = axios.create({
    // axios中请求配置有baseURL选项，表示请求URL公共部分
    baseURL: process.env.VUE_APP_BASE_API,
    // 超时
    timeout: 10000
})

service.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        console.log(error);
        Promise.reject(error);
    }
)

service.interceptors.response.use(
    res => {
        if (res.data.code !== 2000) {
            Notification.warning(res.data.msg)
        }
        return res;
    },
    error => {
        if (error.message.includes('Network Error')) {
            Notification.warning('请求超时，请检查网络后重试！')

            return Promise.reject(error);
        }
        Notification.error(error.message)
        return Promise.reject(error);
    }
)



export default service
